<template>
  <div class="hello">
      <canvas ref="frame"/>
  </div>
</template>

<script>
import jsnes from 'jsnes'


export default {
  name: 'HelloWorld',
  data () {
    return {
     
    }
  },
  created(){
    let canvasFrame=this.$refs.frame
    var nes = new jsnes.NES({
        onFrame: function(frameBuffer) {
           console.log(frameBuffer)
        },
        onAudioSample: function(left, right) {
            // ... play audio sample
        }
    });

    // Read ROM data from disk (using Node.js APIs, for the sake of this example)
    const fs = require('fs');
    console.log(fs)
    var romData = fs.readFileSync('./星之卡比.NES', {encoding: 'binary'});
    
    // Load ROM data as a string or byte array
    nes.loadROM(romData);

    // Run frames at 60 fps, or as fast as you can.
    // You are responsible for reliable timing as best you can on your platform.
    nes.frame();
    nes.frame();
    // ...

    // Hook up whatever input device you have to the controller.
    nes.buttonDown(1, jsnes.Controller.BUTTON_A);
    nes.frame();
    nes.buttonUp(1, jsnes.Controller.BUTTON_A);
    nes.frame();
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
